﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ObjectTransposeApi;
using System.Collections;

namespace ObjectTransposeApiSystemTest.TestFixture
{
    [TestFixture]
    public class ToValueSimpleTestFixture
    {
        public class SingleStructure
        {
            public string Value { get; set; }
        }

        public class DoubleStructure
        {
            public string ValueOne { get; set; }
            public int ValueTwo { get; set; }
        }

        [Test]
        public void NullTest()
        {
            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(null);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, null);
        }

        [Test]
        public void SingleTest()
        {
            var source = new
            {
                Value = "test"
            };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, source.Value);
        }

        [Test]
        public void SingleTypeWrongTest()
        {
            var source = new
            {
                Value = 123
            };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, null);
        }

        [Test]
        public void SingleNameWrongTest()
        {
            var source = new
            {
                ValueOne = "test"
            };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, null);
        }

        [Test]
        public void DoubleTest()
        {
            var source = new
            {
                ValueOne = "test",
                ValueTwo = 123
            };

            DoubleStructure doubleStructure = ObjectToValue.Copy<DoubleStructure>(source);

            // make sure the field was set
            Assert.AreEqual(doubleStructure.ValueOne, source.ValueOne);
            Assert.AreEqual(doubleStructure.ValueTwo, source.ValueTwo);
        }


        [Test]
        public void ListOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void ListTwoTest()
        {
            var sourceOne = new
            {
                Value = "test1"
            };

            var sourceTwo = new
            {
                Value = "test2"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);
            sources.Add(sourceTwo);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceTwo.Value);
        }

        [Test]
        public void ArrayListOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            ArrayList sources = new ArrayList();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void HashtableOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            Hashtable sources = new Hashtable();

            sources.Add(1, sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void DictionaryOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            Dictionary<object, object> sources = new Dictionary<object, object>();

            sources.Add(1, sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void ArrayOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            object[] sources = new object[] { sourceOne };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void IEnumerableOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            object[] sources = new object[] { sourceOne };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>((IEnumerable)sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void IEnumerableGenericOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            object[] sources = new object[] { sourceOne };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>((IEnumerable<object>)sources);

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void IEnumeratorOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            object[] sources = new object[] { sourceOne };

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources.GetEnumerator());

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }

        [Test]
        public void IEnumeratorGenericOneTest()
        {
            var sourceOne = new
            {
                Value = "test"
            };

            List<object> sources = new List<object>();

            sources.Add(sourceOne);

            SingleStructure singleStructure = ObjectToValue.Copy<SingleStructure>(sources.GetEnumerator());

            // make sure the field was set
            Assert.AreEqual(singleStructure.Value, sourceOne.Value);
        }
    }
}
